package com.company.service.impl;

import com.company.entity.Type;
import com.company.service.Liebiao;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;

public class ShangChuanImpl implements Liebiao {
    xiaoshuoImpl xiaoshuo = new xiaoshuoImpl();



    @Override
    public void liebiao(List list) {
        Scanner sc = new Scanner(System.in);
        Type type = new Type();
        System.out.println("------------小说列表结束------------");

        while (true){
            System.out.println("0.返回上一级菜单");
            System.out.println("-1.上传小说");
            System.out.println("输入小说序号阅读：");
            String xuanze = sc.next();
            switch (xuanze){
                case "0":

                    xiaoshuo.liebiao(list);

                    break;
                case "-1":
                    System.out.println("请输入小说名称：");
                    type.setName(sc.next());
                    System.out.println("请输入小说作者：");
                    type.setZuozhe(sc.next());
                    System.out.println("请输入小说简介：");
                    type.setJianjie(sc.next());
                    System.out.println("请输入小说地址：(D:\\露\\demo\\)");
                    type.setDizhi(sc.next());
                    File file = new File("D:\\露\\demo\\"+type.getName()+".txt");


                    boolean b= file.exists();
                    if (b==true){

                    }else {
                        try {

                            file.createNewFile();
                            System.out.println("小说地址："+file.getPath() );


                            System.out.println("1返回上一级");

                            int xuan = sc.nextInt();
                            if (xuan==1){
                                this.xiaoshuo.liebiao(list);
                                Type type1 = new Type();


                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        break;
                    }

                    list.add(type.getName());
                    list.add(type.getZuozhe());
                    list.add(type.getJianjie());
                    list.add(type.getDizhi());


                    break;
                default:
                    System.out.println("您的输入有误请重新输入：");
                    xuanze = sc.next();
                    break;
            }
            break;
        }
    }
}
